package com.jbm.jbmsupplier.zp.FactouryActivity.FacturyChatBaseAdapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.zp.adapters.ChatMsgViewAdapter;
import com.jbm.jbmsupplier.zp.entity.ChatMsgEntity;
import com.jbm.jbmsupplier.zp.liaotian.ShowImageView;
import com.jbm.jbmsupplier.zp.sqldata.MySqliteUtlis;
import com.jbm.jbmsupplier.zp.utils.ClassUser;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

import static com.jbm.jbmsupplier.zp.utils.TableName.BUDDY;

/**
 * Created by 家帮忙 on 2017/7/17.
 */

public class ReceAdapterSendPic implements ChatBaseInterfaces {
    @Override
    public void setDataAdapter(final ChatMsgViewAdapter.ViewHolder viewHolder, int position, int type,final List<ChatMsgEntity> coll, final String stShowSendTime, final Context context, int toid) {

     if (coll.get(position).getTags()==1){
         viewHolder.iv_userheads.setImageDrawable(context.getResources().getDrawable(R.mipmap.pic));

     }else

        if (MySqliteUtlis.GetInstan(context).showFriendsToID(BUDDY, toid ,new ClassUser(context).getLogin()).getHead_portrait().equals("")){
            viewHolder.iv_userheads.setImageDrawable(context.getResources().getDrawable(R.mipmap.pic));

        }else {
            ImageOptions i=new ImageOptions.Builder().setCircular(true).build();
            x.image().bind(viewHolder.iv_userheads,MySqliteUtlis.GetInstan(context).showFriendsToID(BUDDY , toid,new ClassUser(context).getLogin()).getHead_portrait(),i);
        }
        x.image().bind(viewHolder.imtv_chatcontent,coll.get(position).getRoute());
        viewHolder.tvSendTime.setText(stShowSendTime);
        viewHolder.tvUserName.setText(coll.get(position).getName());
        viewHolder.imtv_chatcontent.setTag(position+"");
        viewHolder.imtv_chatcontent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context,ShowImageView.class).putExtra("image",coll.get(Integer.parseInt(viewHolder.imtv_chatcontent.getTag()+"")).getRoute()));
            }
        });
    }
}
